package com.collect.cameroon.zhiScene.zhiCollection.zhiGroup.zhiPerformance.zhiB1;

import android.content.Context;

import com.collect.cameroon.zhiBase.BasePresenter;
import com.collect.cameroon.zhiBase.BaseSubscriber;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRCollectGrouperPerformanceListEntity;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRCollectMemberPerformanceListEntity;
import com.collect.cameroon.zhiBean.zhiSend.ZHISPerfermanceEntity;
import com.collect.cameroon.zhiNetApi.ZHIHttpApiProvider;
import com.collect.cameroon.zhiNetApi.ZHIHttpResponse;
import com.collect.cameroon.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHIPerformanceGroupB1Presenter extends BasePresenter<ZHIPerformanceGroupB1Contract.View> implements ZHIPerformanceGroupB1Contract.Presenter {

    @Inject
    public ZHIPerformanceGroupB1Presenter() {

    }

    @Override
    public void getGroupB1B2PerformanceList(Context context, ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ZHIRCollectGrouperPerformanceListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRCollectGrouperPerformanceListEntity>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRCollectGrouperPerformanceListEntity zhirCollectGrouperPerformanceListEntity = (ZHIRCollectGrouperPerformanceListEntity) object;
                            mView.onGetGroupB1B2PerformanceList(zhirCollectGrouperPerformanceListEntity, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().groupB1Performance(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void getMemberB1B2PerfermanceList(Context context, final ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showDialog) {
        BaseSubscriber<ZHIHttpResponse<ZHIRCollectMemberPerformanceListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRCollectMemberPerformanceListEntity>>(context, this, showDialog) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRCollectMemberPerformanceListEntity zhirCollectMemberPerformanceListEntity = (ZHIRCollectMemberPerformanceListEntity) object;
                            mView.onGetMemberB1B2PerfermanceList(zhirCollectMemberPerformanceListEntity, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().perfermanceMemberB1B2List(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
